package org.noip.milhous;

import java.util.HashMap;
import java.util.Map;

import org.noip.milhous.annotations.dbVar;
import org.noip.milhous.annotations.length;
import org.noip.milhous.annotations.transientVar;

public class KEY_COLUMN_USAGE implements CustomFieldMapping, TableNameMapping
{
	@transientVar
	public Map<String, String> javaToDB = new HashMap<String, String>();

	public enum FIELDS
	{
		CONSTRAINT_CATALOG("CONSTRAINT_CATALOG"), CONSTRAINT_SCHEMA("CONSTRAINT_SCHEMA"), CONSTRAINT_NAME("CONSTRAINT_NAME"), TABLE_CATALOG("TABLE_CATALOG"), TABLE_SCHEMA("TABLE_SCHEMA"), TABLE_NAME(
				"TABLE_NAME"), COLUMN_NAME("COLUMN_NAME"), ORDINAL_POSITION("ORDINAL_POSITION"), POSITION_IN_UNIQUE_CONSTRAINT("POSITION_IN_UNIQUE_CONSTRAINT"), REFERENCED_TABLE_SCHEMA(
				"REFERENCED_TABLE_SCHEMA"), REFERENCED_TABLE_NAME("REFERENCED_TABLE_NAME"), REFERENCED_COLUMN_NAME("REFERENCED_COLUMN_NAME");
		public String dbField;

		private FIELDS(String s)
			{
				dbField = s;
			}

		public String getDatabaseFieldName()
			{
				return "`" + dbField + "`";
			}

	}

	@dbVar
	@length("512")
	private String CONSTRAINT_CATALOG = null;

	@dbVar
	@length("64")
	private String CONSTRAINT_SCHEMA = null;

	@dbVar
	@length("64")
	private String CONSTRAINT_NAME = null;

	@dbVar
	@length("512")
	private String TABLE_CATALOG = null;

	@dbVar
	@length("64")
	private String TABLE_SCHEMA = null;

	@dbVar
	@length("64")
	private String TABLE_NAME = null;

	@dbVar
	@length("64")
	private String COLUMN_NAME = null;

	@dbVar
	private Integer ORDINAL_POSITION = null;

	@dbVar
	private Integer POSITION_IN_UNIQUE_CONSTRAINT = null;

	@dbVar
	@length("64")
	private String REFERENCED_TABLE_SCHEMA = null;

	@dbVar
	@length("64")
	private String REFERENCED_TABLE_NAME = null;

	@dbVar
	@length("64")
	private String REFERENCED_COLUMN_NAME = null;

	public String getCONSTRAINT_CATALOG()
		{
			return CONSTRAINT_CATALOG;
		}

	public void setCONSTRAINT_CATALOG(String constraint_catalog)
		{
			this.CONSTRAINT_CATALOG = constraint_catalog;
		}

	public String getCONSTRAINT_SCHEMA()
		{
			return CONSTRAINT_SCHEMA;
		}

	public void setCONSTRAINT_SCHEMA(String constraint_schema)
		{
			this.CONSTRAINT_SCHEMA = constraint_schema;
		}

	public String getCONSTRAINT_NAME()
		{
			return CONSTRAINT_NAME;
		}

	public void setCONSTRAINT_NAME(String constraint_name)
		{
			this.CONSTRAINT_NAME = constraint_name;
		}

	public String getTABLE_CATALOG()
		{
			return TABLE_CATALOG;
		}

	public void setTABLE_CATALOG(String table_catalog)
		{
			this.TABLE_CATALOG = table_catalog;
		}

	public String getTABLE_SCHEMA()
		{
			return TABLE_SCHEMA;
		}

	public void setTABLE_SCHEMA(String table_schema)
		{
			this.TABLE_SCHEMA = table_schema;
		}

	public String getTABLE_NAME()
		{
			return TABLE_NAME;
		}

	public void setTABLE_NAME(String table_name)
		{
			this.TABLE_NAME = table_name;
		}

	public String getCOLUMN_NAME()
		{
			return COLUMN_NAME;
		}

	public void setCOLUMN_NAME(String column_name)
		{
			this.COLUMN_NAME = column_name;
		}

	public Integer getORDINAL_POSITION()
		{
			return ORDINAL_POSITION;
		}

	public void setORDINAL_POSITION(Integer ordinal_position)
		{
			this.ORDINAL_POSITION = ordinal_position;
		}

	public Integer getPOSITION_IN_UNIQUE_CONSTRAINT()
		{
			return POSITION_IN_UNIQUE_CONSTRAINT;
		}

	public void setPOSITION_IN_UNIQUE_CONSTRAINT(Integer position_in_unique_constraint)
		{
			this.POSITION_IN_UNIQUE_CONSTRAINT = position_in_unique_constraint;
		}

	public String getREFERENCED_TABLE_SCHEMA()
		{
			return REFERENCED_TABLE_SCHEMA;
		}

	public void setREFERENCED_TABLE_SCHEMA(String referenced_table_schema)
		{
			this.REFERENCED_TABLE_SCHEMA = referenced_table_schema;
		}

	public String getREFERENCED_TABLE_NAME()
		{
			return REFERENCED_TABLE_NAME;
		}

	public void setREFERENCED_TABLE_NAME(String referenced_table_name)
		{
			this.REFERENCED_TABLE_NAME = referenced_table_name;
		}

	public String getREFERENCED_COLUMN_NAME()
		{
			return REFERENCED_COLUMN_NAME;
		}

	public void setREFERENCED_COLUMN_NAME(String referenced_column_name)
		{
			this.REFERENCED_COLUMN_NAME = referenced_column_name;
		}

	public String getJavaToDbMapping(String javaName)
		{
			if (javaToDB == null || javaToDB.isEmpty())
				{
					for (FIELDS f : FIELDS.values())
						javaToDB.put(f.name(), f.dbField);
				}
			return javaToDB.get(javaName.toUpperCase());
		}

	public String getRealTableName()
		{
			return this.getClass().getSimpleName();
		}

	public String toString()
		{
			return " " + CONSTRAINT_CATALOG + " " + CONSTRAINT_SCHEMA + " " + CONSTRAINT_NAME + " " + TABLE_CATALOG + " " + TABLE_SCHEMA + " " + TABLE_NAME + " " + COLUMN_NAME + " " + ORDINAL_POSITION + " " + POSITION_IN_UNIQUE_CONSTRAINT + " " + REFERENCED_TABLE_SCHEMA + " " + REFERENCED_TABLE_NAME + " " + REFERENCED_COLUMN_NAME + " ";
		}
}
